<!DOCTYPE html>
<html  lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>缺货管理</title>
    <th:block th:include="~{common/common::commonHead}"/>
</head>
<!-- /Head -->
<!-- Body -->
<body>
<!-- Page Body -->
<div class="page-body">
    <div class="panel panel-primary">
        <div class="panel-heading bg-blue">
            缺货信息
        </div>
        <div class="widget-body grid-table">
            <div class="toolbar">
                <div class="fl-left">
                    <button data-menu-id="020401" data-click="deliver()" class="btn btn-blue shiny">确认发货</button>
                    <button data-menu-id="020402" data-click="confirm()" class="btn btn-blue shiny">确认补货</button>
                </div>
                <div class="toolbar-right">
                    <div class="fl-right">
                        <div class="btn-group" role="group">
                            <button data-click="toggleFilter()" class="btn btn-default text-center">
                                <i class="fa fa-filter fa-fw"></i>
                            </button>
                            <button data-click="refresh('stockOutList')" class="btn btn-default">
                                <i class="fa fa-refresh fa-fw"></i>
                            </button>
                            <button data-click="download('stockOutList')" class="btn btn-default">
                                <i class="fa fa-download fa-fw"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            <div id="stockOutList"></div>
            <!--筛选-->
            <form class="filter search-content form-horizontal" role="form">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label"> 供应商 </label>
                        <div class="col-xs-8">
                            <div class="iconic-input right">
                                <select name="accountSupplier" class="form-control spinner" data-url="org/listSupplier" data-value="-1" data-value-field="id" data-text-field="orgName" >
                                    <option value="-1">全部</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label"> 监所 </label>
                        <div class="col-xs-8">
                            <div class="iconic-input right">
                                <select name="accountPrisons" class="form-control spinner" data-url="org/listPrison" data-value="-1" data-value-field="id" data-text-field="orgName" >
                                    <option value="-1">全部</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-xs-12">
                    <button type="button" data-click="hideFilter()" class="btn btn-default pull-right">取消</button>
                    <button type="button" data-click="submitFilter('stockOutList')" class="btn btn-blue pull-right">确定</button>
                </div>
            </form>
            <!--筛选-->
        </div><!-- end of panel -->
    </div>

</div>
</body>
<!--  /Body -->
</html>
<script>
    $(function(){
        $("#stockOutList").gridTable({
            url: "goodsReturn/pageGoodsReturn",
            columns: [
                {title: "商品图片", field: "goodsImg", format: toImg},
                {title: "缺货单号", field: "id"},
                {title: "供应商", field: "supplierName"},
                {title: "监所", field: "prisonsName"},
                {title: "商品名称", field: "goodsName"},
                {title: "商品数量", field: "goodsCount",dataType:"number"},
                {title: "状态", field: "statusStr"},
                {title: "创建时间", field: "createTime"}
            ],
            showControl:false,
            onDoubleClickRow:function(){},
            idField: "id"
        });
    });
    function toImg(url) {
        return "<img src='"+url+"' width='40' height='40'>";
    }
    // 确认发货
    function deliver() {
        var gridTable =$$selection.get("gridTable","stockOutList");
        var selectedRows = gridTable.getSelectedRows();
        if(selectedRows.length === 0){
            $.error("未选择任何数据");
            return;
        }
        selectedRows.forEach(function (row) {
            row.setStyleEdit();
        });
        $.confirm({
            title: "发货确认",
            icon: "fa fa-question-circle-o",
            content: "<p>确认选中的 <span class='text-danger'>" + selectedRows.length + "</span> 商品发货吗？</p>",
            theme: "modern",
            type: "orange",
            buttons:{
                ok:{
                    text: "确认",
                    btnClass: "btn-primary",
                    action:function(){
                        var arr=[];
                        selectedRows.forEach(function(row){
                            arr.push(row.getData().id);
                        });
                        var idStr =arr.join(",");
                        var scb = function () {
                            $.success("操作成功：修改了" + selectedRows.length + "条数据");
                            gridTable.reloadData();
                        };
                        var ecb = function (error) {
                            $.error(error.msg);
                            selectedRows.forEach(function (row) {
                                row.unsetStyleEdit();
                            });
                        };
                        $.doAjax("goodsReturn/confirmBackGoods",{"idStr":idStr},scb,ecb);
                    }
                },
                cancel: {
                    text: "取消",
                    btnClass: "btn-success",
                    action: function () {
                        selectedRows.forEach(function (row) {
                            row.unsetStyleEdit();
                        });
                    }
                }
            }
        });
    }
    function confirm() {
        var gridTable =$$selection.get("gridTable","stockOutList");
        var selectedRows = gridTable.getSelectedRows();
        if(selectedRows.length === 0){
            $.error("未选择任何数据");
            return;
        }
        selectedRows.forEach(function (row) {
            row.setStyleEdit();
        });
        $.confirm({
            title: "收货确认",
            icon: "fa fa-question-circle-o",
            content: "<p>确认收到了选中的 <span class='text-danger'>" + selectedRows.length + "</span> 商品吗？</p>",
            theme: "modern",
            type: "orange",
            buttons:{
                ok:{
                    text: "确认",
                    btnClass: "btn-primary",
                    action:function(){
                        var arr=[];
                        selectedRows.forEach(function(row){
                            arr.push(row.getData().id);
                        });
                        var idStr =arr.join(",");
                        var scb = function () {
                            $.success("操作成功：修改了" + selectedRows.length + "条数据");
                            gridTable.reloadData();
                        };
                        var ecb = function (error) {
                            $.error(error.msg);
                            selectedRows.forEach(function (row) {
                                row.unsetStyleEdit();
                            });
                        };
                        $.doAjax("goodsReturn/confirmGoodsReturn",{"idStr":idStr},scb,ecb);
                    }
                },
                cancel: {
                    text: "取消",
                    btnClass: "btn-success",
                    action: function () {
                        selectedRows.forEach(function (row) {
                            row.unsetStyleEdit();
                        });
                    }
                }
            }
        });
    }

</script>